<?php
namespace app\custom\service;

use app\common\library\Service;
use think\Db;

class CustomSetting extends Service
{
    use \app\common\library\traits\Model;

    // 模型验证
    protected $modelValidate = null;
    // 批量验证
    protected $batchValidate = null;

    protected function _initialize() {
        parent::_initialize();
        $this->model = model('custom/custom_setting');
    }
    
    //客户管理后台配置
    public function setting($data = []){
        if (empty($data['current_id'])){
            $this->error = '客户标识不能为空';
            return false;
        }
        Db::startTrans();
        try{
            $result = $this->model->where('current_id','=',$data['current_id'])->find();
            if (empty($result->id)){
                $this->model->save($data);
                $result = $this->model;
            }else{
                $result->isUpdate(true)->save($data);
            }
        }catch(\Exception $e) {
            $e->getMessage();
            Db::rollback();
            return false;
        }
        Db::commit();
        return $result;
    }

    //获取客户配置
    public function get($current_id = ''){
        return $this->model->where('current_id','=',$current_id)->find();
    }
}